﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using EntityObject;
using System.Data;
using SharedLibraries;
using ThangNM_LIB.FUNC;

namespace DataAccessObject
{
    public class UrlChangeDAO : DB_SQL_EXT
    {
        public Boolean Insert_Update_Delete(UrlChangeEO _UrlChangeEO, Int16 Insert_Update_Delete)
        {
            SqlCommand cmd = new SqlCommand("UrlChange_Insert_Update_Delete");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_iID", _UrlChangeEO.PK_iID));
            cmd.Parameters.Add(new SqlParameter("@sUrlSrc", NullEx.getNullValue(_UrlChangeEO.sUrlSrc)));
            cmd.Parameters.Add(new SqlParameter("@sUrlDes", NullEx.getNullValue(_UrlChangeEO.sUrlDes)));
            cmd.Parameters.Add(new SqlParameter("@bStatus", NullEx.getNullValue(_UrlChangeEO.bStatus)));
            cmd.Parameters.Add(new SqlParameter("@Insert_Update_Delete", Insert_Update_Delete));
            return ExecuteNonQuery_RetBool(cmd, true);
        }

        public DataTable SelectList()
        {
            SqlCommand cmd = new SqlCommand("UrlChange_SelectList");
            cmd.CommandType = CommandType.StoredProcedure;
            return GetDataTable(cmd);
        }

        public UrlChangeEO SelectBy_sUrlSrc(String sUrlSrc)
        {
            SqlCommand cmd = new SqlCommand("UrlChange_SelectBy_sUrlSrc");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@sUrlSrc", sUrlSrc));
            return FunctionDO(GetDataTable(cmd));
        }

        public UrlChangeEO FunctionDO(DataTable input)
        {
            List<UrlChangeEO> lst = new List<UrlChangeEO>();
            lst = (List<UrlChangeEO>)ConvertEx.ConvertDataTableToListObject<UrlChangeEO>(input, lst.GetType());
            if (CommonsCheck.ListObject_OK(lst))
                return lst[0];
            else
                return null;
        }
    }
}